package com.sea.supply.service.impl;


import com.sea.supply.entity.QualityProduceDetail;
import com.sea.supply.entity.QualityProduceType;
import com.sea.supply.mapper.QualityProduceDetailMapper;
import com.sea.supply.service.QualityProduceDetailService;
import com.sea.supply.service.QualityProduceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 陈鸿飞
 */
@Service
public class QualityProduceDetailServiceImpl implements QualityProduceDetailService {

    @Autowired
    private QualityProduceDetailMapper qualityProduceDetailMapper;
    @Autowired
    private QualityProduceTypeService qualityProduceTypeService;

    @Override
    public int save(QualityProduceDetail qualityProduceDetail) {
        return qualityProduceDetailMapper.insert(qualityProduceDetail);
    }

    @Override
    public List<QualityProduceDetail> findByProduceId(Integer produceId) {
        return qualityProduceDetailMapper.findByProduceId(produceId);
    }

    @Override
    public void addDetail(Integer produceId) {
        List<QualityProduceType> list = qualityProduceTypeService.findByCnd(null);
        if(list.size()>0){
            for(QualityProduceType produceType:list){
                QualityProduceDetail qualityProduceDetail=new QualityProduceDetail();
                qualityProduceDetail.setProduceId(produceId);
                qualityProduceDetail.setProduceType(produceType.getProduceType());
                qualityProduceDetail.setProduceName(produceType.getProduceName());
                save(qualityProduceDetail);
            }
        }
    }

    @Override
    public void updateQualityStatus(QualityProduceDetail qualityProduceDetail) {
        Integer[] ids = qualityProduceDetail.getIds();
        for(Integer id:ids){

            QualityProduceDetail detail=new QualityProduceDetail();
            detail.setId(id);
            detail.setQualityStatus(qualityProduceDetail.getQualityStatus());
            qualityProduceDetailMapper.update(detail);
        }
     
    }
}
